import java.sql.*;

public class Demo05 {
    public static void main(String[] args) throws SQLException {
        //        1.获取链接对象
        Connection conn=
                DriverManager.getConnection(
                        "jdbc:mysql://localhost:3306/empdb?characterEncoding=utf8&serverTimezone=Asia/Shanghai","root","root"
                );
        System.out.println(conn);

//        2.创建执行SQL语句对象
        Statement s= conn.createStatement();
        ResultSet rs=s.executeQuery("select id,name from hero");
//        从结果集对象中遍历数据
        while (rs.next()){
            int id=rs.getInt("id");
            String name= rs.getString("name");
            System.out.println(id+":"+name);
        }
        conn.close();
    }
}
